package zgc.demo.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import zgc.demo.consumer.entity.Goods;
import zgc.demo.consumer.service.OrderService;

import java.util.List;

@RestController
@RequestMapping("/order1")
public class OrderController01 {


    @Autowired
    private RestTemplate restTemplate;

    /**
     * restTemplate实现远程接口调用
     * 这样做的缺点是ip+port需要写死
     *
     * @param goodsId
     * @return
     */
    @GetMapping("/getGoodsById/{goodsId}")
    public Goods getGoodsById(@PathVariable("goodsId") String goodsId) {
        System.out.println("获取商品中......");
        String url = "http://127.0.0.1:8080/goods/getGoodsById/" + goodsId;
        return restTemplate.getForObject(url, Goods.class);
    }
}
